package net.ciklum.svnnotify;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;

public class SettingsActivity extends PreferenceActivity {
	public static final String UPDATE_PREF = "updatePref";
	public static final String PREF = "preferences";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		addPreferencesFromResource(R.xml.svn_pref);
		setUpdatePreferences();
	}

	private void setUpdatePreferences() {
		ListPreference updatePref = (ListPreference) findPreference(UPDATE_PREF);
		updatePref.setSummary(updatePref.getValue());

		updatePref
				.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
					public boolean onPreferenceChange(Preference preference,
							Object newValue) {
						ListPreference listPreference = (ListPreference) preference;
						listPreference.setSummary((String) newValue);

						SharedPreferences mySharedPreferences = getSharedPreferences(
								PREF, Activity.MODE_PRIVATE);
						SharedPreferences.Editor editor = mySharedPreferences
								.edit();
						editor.putString(UPDATE_PREF, (String) newValue);
						editor.commit();
						return true;
					}
				});
	}
}